//
//  ViewFactory.swift
//  MT
//
//  Created by zhang qiang on 2018/11/21.
//  Copyright © 2018年 张强. All rights reserved.
//

import Foundation
import MJRefresh

public enum MTRefreshStatus {
    case none
    case beginHeaderRefresh
    case endHeaderRefresh
    case beginFooterRefresh
    case endFooterRefresh
    case noMoreData
    case removeFooter
}

public class ViewFactory{
    
    public static func normalHeader(refreshBlock: @escaping MJRefreshComponentAction) -> MJRefreshNormalHeader {
        
        let header = MJRefreshNormalHeader.init(refreshingBlock: refreshBlock)
        
        header.setTitle("下拉刷新", for: .idle)
        header.setTitle("松开刷新", for: .pulling)
        header.setTitle("正在加载", for: .refreshing)
        
        header.stateLabel?.font = HelveticaNeueFont(13.0)
        header.stateLabel?.textColor = UIColor.init(hex: 0xbababa)
        header.lastUpdatedTimeLabel?.isHidden = true
        
        return header
        
    }
    
   public static func normalFooter(refreshBlock: @escaping MJRefreshComponentAction) -> MJRefreshFooter {
    let footer = MJRefreshAutoNormalFooter.init(refreshingBlock: refreshBlock)
        
        footer.setTitle("上拉加载", for: .idle)
        footer.setTitle("松开刷新", for: .pulling)
        footer.setTitle("正在加载", for: .refreshing)
        
    footer.stateLabel?.font = HelveticaNeueFont(13.0)
    footer.stateLabel?.textColor = UIColor.init(hex: 0xbababa)
        
        return footer
    }
    
   public static func normalHeader(target: Any, selector: Selector) -> MJRefreshNormalHeader {
    let header = MJRefreshNormalHeader.init(refreshingTarget: target, refreshingAction:selector)
        
        header.setTitle("下拉刷新", for: .idle)
        header.setTitle("松开刷新", for: .pulling)
        header.setTitle("正在加载", for: .refreshing)
        
    header.stateLabel?.font = HelveticaNeueFont(13.0)
    header.stateLabel?.textColor = UIColor.init(hex: 0xbababa)
    header.lastUpdatedTimeLabel?.isHidden = true
        
        return header
    }
    
    public static func normalHiddenTitleHeader(target: Any, selector: Selector) -> MJRefreshNormalHeader {
        let header = MJRefreshNormalHeader.init(refreshingTarget: target, refreshingAction:selector)
        
        header.setTitle("", for: .idle)
        header.setTitle("", for: .pulling)
        header.setTitle("", for: .refreshing)
        
        header.stateLabel?.font = HelveticaNeueFont(13.0)
        header.stateLabel?.textColor = UIColor.init(hex: 0xbababa)
        header.lastUpdatedTimeLabel?.isHidden = true
        header.arrowView?.isHidden = true
        
        return header
    }
    
   public static func normalFooter(target: Any, selector: Selector) -> MJRefreshBackNormalFooter {
    let footer = MJRefreshBackNormalFooter.init(refreshingTarget: target, refreshingAction: selector)
        
        footer.setTitle("下拉刷新", for: .idle)
        footer.setTitle("松开刷新", for: .pulling)
        footer.setTitle("正在加载", for: .refreshing)
        footer.setTitle("没有更多了", for: .noMoreData)
        
    footer.stateLabel?.font = HelveticaNeueFont(13.0)
    footer.stateLabel?.textColor = UIColor.init(hex: 0xbababa)
        
        return footer
    }
    
    
    /// 空数据页面配置
    /// - Parameters:
    ///   - title: title description
    ///   - image: image description
    ///   - tapViewBlock: tapViewBlock description - 点击空页面block
    public static func emptySetView(_ title: NSAttributedString? = nil,
                                    _ image: UIImage? = nil,
                                    _ tapViewBlock: (() -> ())? = nil) -> EmptySetView {
        let v = EmptySetView.normal()
        if title == nil {
            let attribute = [NSAttributedString.Key.font: PingFangSCRegularFont(14), NSAttributedString.Key.foregroundColor: UIColor(hex: 0x5d5d5d)]
            v.title = NSAttributedString(string: "这里空空如也...", attributes: attribute)
        } else {
            v.title = title
        }
        if image == nil {
            v.image = UIImage(named: "icon_empty")
        } else {
            v.image = image
        }
        
        v.tapViewBlock = { view in
            tapViewBlock?()
        }
        return v
    }
}
